package com.service.impl;

import com.config.Result;
import com.dao.UserDao;
import com.pojo.User;
import com.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    @Transactional
    public User selectUserByPassword(User user) {
        System.out.println("进入service层 ===============================");
        User loginuser = userDao.selectUserByPassword(user);
        System.out.println("loginuser = =======================" + loginuser);
        if (loginuser.getSno() != null){
            User byUsername = userDao.selecrByUsername(user);
            System.out.println("byUsername =========================== " + byUsername);
            return byUsername;
        }
        return loginuser;
    }

    @Override
    @Transactional
    public int updateInfo(User user) {
        int i = userDao.updateInfo(user);
        return i;
    }

    @Override
    @Transactional
    public int updateSno(String sno,String username) {
        return userDao.updateSno(sno,username);
    }

    @Override
    @Transactional
    public User selectByUsername(User user) {
        return userDao.selecrByUsername(user);
    }

    @Transactional
    @Override
    public User findById(User user){
        return userDao.findById(user);
    }

    @Transactional
    @Override
    public User findBySno(String sno) {
        return userDao.findBySno(sno);
    }

    @Transactional
    @Override
    public Integer insertData(User user, String roleId) {
        return userDao.insertData(user, roleId);
    }
}
